import {Base} from "base.js";
import {Config} from "config.js";

class Address extends Base {

    constructor(){
        super();
    }

    setAddressInfo(res){
        var province = res.provinceName || res.province,
            city = res.cityName || res.city,
            county = res.countyName || res.county,
            detail = res.detailInfo || detail;
        var totalDetail = city + county + detail;
        if(!this._isCenterCity(city)){
            totalDetail = province + city + county + detail;
        }
        return totalDetail;        
    }


    // 判断是否为直辖市
    _isCenterCity(name){
        var centerCitys = ['北京市','天津市','上海市','重庆市'],
        falg = centerCitys.indexOf(name) >= 0;
        return falg;
    }

    // 更新保存地址
    submitAddress(data,callback){
        data = this._setUpAddress(data);
        var param = {
            url:"address",
            type:"POST",
            data:data,
            sCallBack:function(res){
                callback && callback(res);
            }
        };
        this.request(param);
    }


    _setUpAddress(res){
        var formData = {
            name:res.userName,
            province:res.provinceName,
            city:res.cityName,
            country:res.countyName,
            mobile:res.telNumber,
            detail:res.detailInfo
        };
        return formData;
    }
}
export{Address};